package com.wuxianedu.wechat.ui.adapter;

import java.util.List;

import com.wuxianedu.wechat.R;
import com.wuxianedu.wechat.bean.PersonBean;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;

public class HeadListAdapter extends BaseAdapter{
	
	private Context context;
	
	private List<PersonBean> list;
	
	public HeadListAdapter(Context context,List<PersonBean> list) {
		this.context = context;
		this.list = list;
	}
	
	@Override
	public int getCount() {
		return list.size();
	}

	@Override
	public Object getItem(int position) {
		return list.get(position);
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		ViewHolder holder;
		if(convertView == null){
			convertView = LayoutInflater.from(context).inflate(R.layout.activity_headlist_item, null);
			holder = new ViewHolder();
			holder.image_item = (ImageView) convertView.findViewById(R.id.image_item);
			convertView.setTag(holder);
		}else{
			holder = (ViewHolder) convertView.getTag();
		}
		
		if(list.size() > 0){
			PersonBean person = list.get(position);
			holder.transParent = person.isHalfTransparent();
			holder.image_item.setImageResource(person.getHead());
			if(holder.transParent){
				holder.image_item.setAlpha(0.5f);
			}else{
				holder.image_item.setAlpha(1.0f);
			}
		}
		
		
		
		return convertView;
	}
	
	public class ViewHolder{
		ImageView image_item;
		boolean transParent;
	}

}
